<?php
/**
 * 商户端
 * 上传图片视频文件管理
 */

namespace App\store\controllers\common;

use App\store\models\UploadModel;
use App\store\services\CommonServices;
use App\store\controllers\StoreBaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


class UploadController extends StoreBaseController
{

    /**
     * 上传图片或者视频文件
     */
    public function upload(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            UploadModel::rules(),
            UploadModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        // 获取文件
        $file = $request->file('file');
        $list = CommonServices::uploads($data, $file);
        if (isset($list['msg'])) {
            return errorJson($list['msg'], []);
        }
        return successJson('ok', $list);
    }

}

